 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Entities;
using Logic;


namespace Application1
{
    public partial class Form1 : Form
    {
        static Division division = DivisionFactory.CreateDivision();
        List<AbstractVegetables> vegetables = division.Vegetables;
        public Form1()
        {
            InitializeComponent();

            foreach (AbstractVegetables vegetable in vegetables)
            {
                listBox1.Items.Add(vegetable.Name + "  " + vegetable.Calorificvalue);
            }
            UpdateLength();
        }
        public void UpdateLength()
        {
            DivisionCalculator divisionCalculator = new DivisionCalculator();
             int totalPrice = divisionCalculator.CalculatePrice(division);
             label1.Text = "Общая калорийность" + totalPrice;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2(this, division, vegetables);
            form2.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2(this, division, vegetables, listBox1.SelectedIndex);
            form2.Show();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            vegetables.RemoveAt(listBox1.SelectedIndex);
            listBox1.Items.RemoveAt(listBox1.SelectedIndex);
            listBox1.Refresh();
            UpdateLength();

        }

        private void button4_Click(object sender, EventArgs e)
        {
            Close();
        }


       
    }
}
